package com.haierp.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.stereotype.Service;

import com.baomidou.framework.service.impl.SuperServiceImpl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.haierp.mapper.WxSessionMapper;
import com.haierp.model.WxSession;
import com.haierp.service.IWxSessionService;

@Service("wxSessionService")
public class WxSessionServiceImpl extends SuperServiceImpl<WxSessionMapper, WxSession>  implements IWxSessionService {
	
	private Map<String,WxSession> maps = new HashMap<>(); //缓存重启自动加载，手动加载两种方式
	@Override
	public Map<String, WxSession> getMaps() {
		return maps;
	}
	@Override
	public void refreshCookieCache() {
		maps.clear();
		EntityWrapper<WxSession> wrapper = new EntityWrapper<WxSession>();
//		wrapper.where("open_id={0}", openId);
//		Map<String, WxSession> map = new HashMap<>();
		System.out.println("*********refreshCookieCache*****************");
		List<WxSession> wxsessions = this.baseMapper.selectList(wrapper);
		if(wxsessions!=null&&!wxsessions.isEmpty()){
			wxsessions.forEach(wx->maps.put(wx.getCookie(), wx));
		}
		System.out.println(maps);
	}
}
